<h:form id="formPlanoDeReceita" 
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:pe="http://primefaces.org/ui/extensions"
        xmlns:f="http://java.sun.com/jsf/core">

    <script language="JavaScript" src = "scripts/script.js"/>

    <h:panelGrid style="width: 100%" >

        <h:panelGrid columns="3">

            <h:panelGroup>

                <h:outputLabel value="Classificação"/><br/>
                <p:inputText id="classificacao"
                             value="#{planoDeReceitaBean.planoDeReceita.classificacao}" 
                             maxlength="16"
                             style="width: 90px" 
                             readonly="true" 
                             required="true"
                             requiredMessage="O campo classificação é requerido" />

            </h:panelGroup>

            <h:panelGroup>

                <h:outputLabel value="Cat. Econômica" /><br/>
                <p:selectOneMenu value="#{planoDeReceitaBean.planoDeReceita.categoriaEconomicaDeReceita}" 
                                 style="width: 115px"
                                 filter="true" 
                                 filterMatchMode="startsWith"
                                 required="true"
                                 requiredMessage="O campo categoria econômica é requerido" >

                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{planoDeReceitaBean.categoriasEconomicaDeReceita}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" update="origemPorCatEcon"/>

                    <p:ajax event="change" update="sequencia" 
                            listener="#{planoDeReceitaBean.obterSequencia}" />

                    <p:ajax event="change" update="classificacao" 
                            listener="#{planoDeReceitaBean.obterClassificacao}" />

                </p:selectOneMenu>

            </h:panelGroup>
            <h:panelGroup>
                <h:outputLabel value="Origem" /><br/>
                <p:selectOneMenu id="origemPorCatEcon" value="#{planoDeReceitaBean.planoDeReceita.origem}" 
                                 style="width: 250px"
                                 filter="true" 
                                 filterMatchMode="startsWith"
                                 required="true"
                                 requiredMessage="O campo origem é requerido" >

                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{planoDeReceitaBean.origens}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" update="especiePorOrigem"/>

                    <p:ajax event="change" update="sequencia" 
                            listener="#{planoDeReceitaBean.obterSequencia}" />

                    <p:ajax event="change" update="classificacao" 
                            listener="#{planoDeReceitaBean.obterClassificacao}" />

                </p:selectOneMenu>
            </h:panelGroup>
        </h:panelGrid>
        <h:panelGrid columns="2">
            <h:panelGroup>
                <h:outputLabel value="Espécie" /><br/>
                <p:selectOneMenu id="especiePorOrigem" 
                                 value="#{planoDeReceitaBean.planoDeReceita.especie}" 
                                 style="width: 235px" 
                                 required="true"
                                 requiredMessage="O campo espécie é requerido">

                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{planoDeReceitaBean.especies}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" update="rubricaPorEspecie"/>

                    <p:ajax event="change" update="sequencia" 
                            listener="#{planoDeReceitaBean.obterSequencia}" />

                    <p:ajax event="change" update="classificacao" 
                            listener="#{planoDeReceitaBean.obterClassificacao}" />

                </p:selectOneMenu>
            </h:panelGroup>
            <h:panelGroup>
                <h:outputLabel value="Rúbrica" /><br/>
                <p:selectOneMenu id="rubricaPorEspecie" 
                                 value="#{planoDeReceitaBean.planoDeReceita.rubrica}" 
                                 style="width: 235px" 
                                 required="true"
                                 requiredMessage="O campo rúbrica é requerido">

                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{planoDeReceitaBean.rubricas}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" update="alineaPorEspecie"/>

                    <p:ajax event="change" update="sequencia" 
                            listener="#{planoDeReceitaBean.obterSequencia}" />

                    <p:ajax event="change" update="classificacao" 
                            listener="#{planoDeReceitaBean.obterClassificacao}" />

                </p:selectOneMenu>
            </h:panelGroup>
        </h:panelGrid>
        <h:panelGrid columns="2">
            <h:panelGroup>
                <h:outputLabel value="Alínea" /><br/>
                <p:selectOneMenu id="alineaPorEspecie" 
                                 value="#{planoDeReceitaBean.planoDeReceita.alinea}" 
                                 style="width: 235px" 
                                 required="true"
                                 requiredMessage="O campo alínea é requerido" >

                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{planoDeReceitaBean.alineas}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" update="sublineaPorAlinea"/>

                    <p:ajax event="change" update="sequencia" 
                            listener="#{planoDeReceitaBean.obterSequencia}" />

                    <p:ajax event="change" update="classificacao" 
                            listener="#{planoDeReceitaBean.obterClassificacao}" />

                </p:selectOneMenu>
            </h:panelGroup>

            <h:panelGroup>

                <h:outputLabel value="Sublínea" /><br/>
                <p:selectOneMenu id="sublineaPorAlinea" 
                                 value="#{planoDeReceitaBean.planoDeReceita.sublinea}" 
                                 style="width: 235px" 
                                 required="true"
                                 requiredMessage="O campo sublínea é requerido" >

                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{planoDeReceitaBean.sublineas}" />
                    <f:converter converterId="simpleEntityConverter" />

                    <p:ajax event="change" update="sequencia" 
                            listener="#{planoDeReceitaBean.obterSequencia}" />

                    <p:ajax event="change" update="classificacao" 
                            listener="#{planoDeReceitaBean.obterClassificacao}" />

                    <p:ajax event="change" update="descricao" 
                            listener="#{planoDeReceitaBean.obterDescricaoSubAlinea}" />

                </p:selectOneMenu>

            </h:panelGroup>

        </h:panelGrid>        
        <h:panelGrid columns="3">
            <h:panelGroup>

                <h:outputLabel value="Sequência"/><br/>
                <p:inputText id="sequencia"
                             value="#{planoDeReceitaBean.planoDeReceita.sequencia}" 
                             maxlength="2" 
                             style="width: 50px" 
                             required="true"
                             requiredMessage="O campo sequencia é requerido" >

                    <p:ajax event="blur" update="classificacao" 
                            listener="#{planoDeReceitaBean.obterClassificacao}" />

                </p:inputText>
            </h:panelGroup>

            <h:panelGroup>
                <h:outputLabel value="Descrição"/><br/>
                <p:inputText id="descricao"
                             value="#{planoDeReceitaBean.planoDeReceita.descricao}" 
                             style="width: 220px"/>
            </h:panelGroup>
            <h:panelGroup>
                <h:outputLabel value="Tipo" /><br/>
                <p:selectOneMenu value="#{planoDeReceitaBean.planoDeReceita.tipoPlanoDeReceita}" 
                                 style="width: 180px">
                    <f:selectItem itemLabel="Selecione" />
                    <f:selectItems value="#{planoDeReceitaBean.tiposPlanoDeReceita}" />
                    <f:converter converterId="simpleEntityConverter" />
                </p:selectOneMenu>
            </h:panelGroup>
        </h:panelGrid>
        <h:panelGrid columns="1" style="width: 98%">
            <h:panelGroup>
                <h:outputLabel value="Histórico"/><br/>
                <p:inputTextarea value="#{planoDeReceitaBean.planoDeReceita.historico}" 
                                 style="width: 100%" styleClass="up"/>
            </h:panelGroup>
        </h:panelGrid>
    </h:panelGrid>

    <hr/>

    <p:commandButton id="btnGravar" value="Gravar" 
                     actionListener="#{planoDeReceitaBean.adicionarEditarFim}"
                     update="formPlanoDeReceita" />

    <p:commandButton value="Cancelar" 
                     actionListener="#{planoDeReceitaBean.cancelar}"
                     immediate="true"/>

</h:form>


